package org.rsbot.script.util;

public class Timer
{
  private long end;
  private long start;
  private long period;

  public Timer(long paramLong)
  {
    this.period = paramLong;
    this.start = System.currentTimeMillis();
    this.end = (this.start + paramLong);
  }

  public long getElapsed()
  {
    return System.currentTimeMillis() - this.start;
  }

  public long getRemaining()
  {
    if (isRunning()) {
      return this.end - System.currentTimeMillis();
    }
    return 0L;
  }

  public boolean isRunning()
  {
    return System.currentTimeMillis() < this.end;
  }

  public void reset()
  {
    this.end = (System.currentTimeMillis() + this.period);
  }

  public long setEndIn(long paramLong)
  {
    this.end = (System.currentTimeMillis() + paramLong);
    return this.end;
  }

  public String toElapsedString()
  {
    return format(getElapsed());
  }

  public String toRemainingString()
  {
    return format(getRemaining());
  }

  public static String format(long paramLong)
  {
    StringBuilder localStringBuilder = new StringBuilder();
    long l1 = paramLong / 1000L;
    long l2 = l1 / 60L;
    long l3 = l2 / 60L;
    int i = (int)l1 % 60;
    int j = (int)l2 % 60;
    int k = (int)l3 % 60;
    if (k < 10) {
      localStringBuilder.append("0");
    }
    localStringBuilder.append(k);
    localStringBuilder.append(":");
    if (j < 10) {
      localStringBuilder.append("0");
    }
    localStringBuilder.append(j);
    localStringBuilder.append(":");
    if (i < 10) {
      localStringBuilder.append("0");
    }
    localStringBuilder.append(i);
    return localStringBuilder.toString();
  }
}